package com.ruoyi.web.controller.basicData.ruleSetting;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basicData.ruleSetting.domain.AccessorySupplierRelevance;
import com.ruoyi.basicData.ruleSetting.service.IAccessorySupplierRelevanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配件ID和供应商关联Controller
 * 
 * @author YiYuan
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/basicData/ruleSetting/relevance")
public class AccessorySupplierRelevanceController extends BaseController
{
    @Autowired
    private IAccessorySupplierRelevanceService accessorySupplierRelevanceService;

    /**
     * 查询配件ID和供应商关联列表
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:relevance:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccessorySupplierRelevance accessorySupplierRelevance)
    {
        startPage();
        List<AccessorySupplierRelevance> list = accessorySupplierRelevanceService.selectAccessorySupplierRelevanceList(accessorySupplierRelevance);
        return getDataTable(list);
    }

    /**
     * 导出配件ID和供应商关联列表
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:relevance:export')")
    @Log(title = "配件ID和供应商关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccessorySupplierRelevance accessorySupplierRelevance)
    {
        List<AccessorySupplierRelevance> list = accessorySupplierRelevanceService.selectAccessorySupplierRelevanceList(accessorySupplierRelevance);
        ExcelUtil<AccessorySupplierRelevance> util = new ExcelUtil<AccessorySupplierRelevance>(AccessorySupplierRelevance.class);
        util.exportExcel(response, list, "配件ID和供应商关联数据");
    }

    /**
     * 获取配件ID和供应商关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:relevance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accessorySupplierRelevanceService.selectAccessorySupplierRelevanceById(id));
    }

    /**
     * 新增配件ID和供应商关联
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:relevance:add')")
    @Log(title = "配件ID和供应商关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccessorySupplierRelevance accessorySupplierRelevance)
    {
        accessorySupplierRelevance.setCreateBy(getUsername());
        accessorySupplierRelevance.setCreateTime(new Date());
        return toAjax(accessorySupplierRelevanceService.insertAccessorySupplierRelevance(accessorySupplierRelevance));
    }

    /**
     * 修改配件ID和供应商关联
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:relevance:edit')")
    @Log(title = "配件ID和供应商关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccessorySupplierRelevance accessorySupplierRelevance)
    {
        accessorySupplierRelevance.setUpdateBy(getUsername());
        return toAjax(accessorySupplierRelevanceService.updateAccessorySupplierRelevance(accessorySupplierRelevance));
    }

    /**
     * 删除配件ID和供应商关联
     */
    @PreAuthorize("@ss.hasPermi('ruleSetting:relevance:remove')")
    @Log(title = "配件ID和供应商关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(accessorySupplierRelevanceService.deleteAccessorySupplierRelevanceByIds(ids));
    }
}
